package com.example.demo.job;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Component;

/**
 * @author huchen
 * @description
 * @since 2021/11/26 15:22
 */
@Component
@Slf4j
public class MyElasticJob implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {
        switch (shardingContext.getShardingItem()){
            case 0:
                log.info("总分片数："+shardingContext.getShardingTotalCount() + "当前分片：" + shardingContext.getShardingItem()+"执行任务。分片参数为"+shardingContext.getShardingParameter());
                break;
            case 1:
                log.info("总分片数："+shardingContext.getShardingTotalCount() + "当前分片：" + shardingContext.getShardingItem()+"执行任务。分片参数为"+shardingContext.getShardingParameter());
                break;
            case 2:
                log.info("总分片数："+shardingContext.getShardingTotalCount() + "当前分片：" + shardingContext.getShardingItem()+"执行任务。分片参数为"+shardingContext.getShardingParameter());
                break;
        }
    }
}
